package com.dsg.workflow;

import com.dsg.entity.apply.DsgApplyBill;
import com.dsg.service.apply.IDsgApplyPayService;
import com.dsg.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

/**
 * CS加車
 */
@Service
public class WorkflowService7 extends AbstractWorkflowService {
    @Autowired
    IDsgApplyPayService payService;

    @Override
    protected String recalculateNodeName(DsgApplyBill bill) {
        if (Constant.PAY_TYPE_ATP.equals(bill.getPayType())) {
            return NODE_CHECK_CAR_NO;
        } else {
            return NODE_RETURN_CARD;
        }
    }

    @Override
    protected boolean canGoOn(DsgApplyBill bill) throws Exception {
        boolean pass = billService.internalAudit(bill);
        return pass;
    }

    @Override
    protected Set getConditionalNodeSet(DsgApplyBill bill) {
        Set<String> conditionalNodeSet = new HashSet<>();
        if (Constant.PAY_TYPE_ATP.equals(bill.getPayType())) {
            conditionalNodeSet.add(NODE_SUP_APPROVE);
            conditionalNodeSet.add(NODE_DDA);
        } else {
            conditionalNodeSet.add(NODE_SEND_CARD);
        }
        return conditionalNodeSet;
    }

    @Override
    protected boolean needNode(String currNodeName, DsgApplyBill bill, String nodeName) {
        if (Constant.PAY_TYPE_ATP.equals(bill.getPayType())) {
            switch (nodeName) {
                case NODE_DDA:
                case NODE_DEDUCT_ONE:
                    return !lastSuccess(bill);
            }
        } else if (Constant.PAY_TYPE_CDC.equals(bill.getPayType())){
            switch (nodeName) {
                case NODE_DEDUCT_ONE:
                    return !lastSuccess(bill);
            }
        }
        return true;
    }
}
